home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-11 / lcpack.zip / TPACKMEM.PRG < prev   
Text File  |  1993-01-04  |  4KB  |  140 lines

  1. * Program Name: tpackmem.prg * 
  2. * Author: Don L. Powells * 
  3. * (c) 1987 by D. P. & Associates * 
  4. * Created: 8/21/1987 at 15:45 *
  5.  
  6. set color to w/b,b/w,b,b,w/b 
  7. clear 
  8. fname = space(64) 
  9. ? "                          TPACKMEM.PRG" 
  10. ? "     This program demonstrates the mpack program written "+;
  11.         "in C." 
  12. ?"   mpack packs the dbt file holding the memos for the "+;
  13.      "specified dbf."
  14.  
  15. * Get filename
  16. @ 8,5 say "Enter a dbf filename with no extension: "  
  17. @ 9,5 get fname 
  18. read 
  19.  
  20. * Append proper extensions to filename
  21. dbffname = trim(fname) + ".dbf" 
  22. dbtname = trim(fname) + ".dbt" 
  23.  
  24. * Check to see if there is enough diskspace to execute the
  25. * function
  26. if diskspace(0) < filesize(dbtname)
  27.    ? chr(7)
  28.    ? "There is not enough disk space to safely execute this "+;
  29.      "function."
  30.    return
  31. endif
  32.  
  33. * Save the original files to temp files for use with mpack
  34. copy file &dbtname to temp#.dbt>nul 
  35. copy file &dbfname to temp#.dbf>nul 
  36.  
  37. * Pack the file with the COPY TO method
  38. @ 5,0 clear 
  39. @ 7,5 say "Packing " + trim(fname) + ".dbt. with COPY TO method." 
  40. stime = seconds() 
  41. use &fname 
  42. copy to temp 
  43. close databases 
  44. erase &dbfname 
  45. erase &dbtname 
  46. rename temp.dbf to &dbfname 
  47. rename temp.dbt to &dbtname 
  48. etime = seconds() 
  49. ?? chr(7) 
  50. run_time = etime - stime 
  51. ? alltrim(str(run_time)) 
  52. ?? " seconds elapsed." 
  53.  
  54. * Restore temp files to original files
  55. copy file temp#.dbt to &dbtname>nul 
  56. copy file temp#.dbt to &dbfname>nul 
  57.  
  58. * Pack using the mpack method
  59. oldsize = filesize(dbtname) 
  60. @ 9,5 say "Packing " + trim(fname) + ".dbt. with MPACK()." 
  61. stime = seconds() 
  62. errnum = mpack(trim(fname)) 
  63. etime = seconds() 
  64. run_time2 = etime - stime 
  65.  
  66. ?? chr(7) 
  67. ? "The error code returned by MPACK() is: " 
  68. ?? errnum 
  69. ?
  70.  
  71. * Translate the error code into a message 
  72. DO CASE 
  73.    case errnum = 0 
  74.       ? "The memo pack was successfully accomplished!!!" 
  75.    case errnum = 1 
  76.       ? " An improper number of parameters was passed or the "+;
  77.         "parameter " 
  78.       ? "    passed was not a character." 
  79.    case errnum = 2 
  80.       ? " The .dbf file could not be opened. There may not be "+;
  81.         "any file " 
  82.       ? "    handles available. The file may not exist. The "+;
  83.         "attributes may" 
  84.       ? "    be set to hidden." 
  85.    case errnum = 3 
  86.       ?" There was an error reading the signature byte of the "+;
  87.        ".dbf" 
  88.       ?"     header." 
  89.    case errnum = 4 
  90.       ? " The signature byte was not 83H. The .dbf file is a "+;
  91.         "dBASE file" 
  92.       ? "     with a memo field." 
  93.    case errnum = 5 
  94.       ? " There was a problem renaming the old .dbt file. "+;
  95.         "There may" 
  96.       ? "    already be a file in the current directory called " 
  97.       ? "    cpackmem.bak. The .dbt file may not be in the "+;
  98.         "current " 
  99.       ? "    directory." 
  100.    case errnum = 6 
  101.       ? " Can not open the old .dbt file." 
  102.    case errnum = 7 
  103.       ? " Can not create new .dbt file. There may be no file "+;
  104.         "handles " 
  105.       ? "    available. The disk may be full." 
  106.    case errnum = 8 
  107.       ? " Read error reading the first 512 bytes of the old "+;
  108.         ".dbt file." 
  109.    case errnum = 9 
  110.       ? " Write error writing the first 512 bytes of the new "+;
  111.         ".dbt file." 
  112.    case errnum = 10 
  113.       ? " Error moving pointer through .dbf file." 
  114.    case errnum = 11 
  115.       ? " Read error reading the .dbf header." 
  116.    case errnum = 12 
  117.       ? " Error moving pointer to first field descriptor in "+;
  118.         ".dbf file." 
  119.    case errnum = 13 
  120.       ? " Read error reading first field descriptor in .dbf "+;
  121.         "file." 
  122.    case errnum = 14 
  123.       ? " Read error reading a field descriptor in .dbf file." 
  124. endcase 
  125.  
  126. * Report results of function
  127. ? alltrim(str(run_time2)) 
  128. ?? " seconds elapsed when packing with MPACK()." 
  129. ? "MPACK requires "  
  130. ?? alltrim(str((run_time2/run_time)*100))+"% of the time "+;
  131.    "required by COPY TO method." 
  132. newsize = filesize(dbtname) 
  133. ? "Original file size= " + alltrim(str(oldsize)) + space(4) +; 
  134.    "New dbt file size= " + alltrim(str(newsize)) 
  135. saved = oldsize-newsize 
  136. ? alltrim(str(saved)) + " bytes were saved by packing." 
  137. wait 
  138. return 
  139.